package com.lyy.msgtool.config;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import javax.jms.Queue;
import javax.jms.Topic;

@Configuration
public class AmqConfig {
    @Value("${spring.activemq.queue-name:}")
    private String queueName;

    @Value("${spring.activemq.topic-name:}")
    private String topicName;

    @Bean(name = "queue")
    public Queue queue() {
        if(!StringUtils.hasText(queueName)){
            queueName="default";
        }
        return new ActiveMQQueue(queueName);
    }

    @Bean(name = "topic")
    public Topic topic() {
        if(!StringUtils.hasText(topicName)){
            topicName="default";
        }
        return new ActiveMQTopic(topicName);
    }
}
